package com.nefu.huiyi.service.impl;

import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowPrivilegesStatement;
import com.baomidou.mybatisplus.core.assist.ISqlRunner;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.nefu.huiyi.entity.Doctor;
import com.nefu.huiyi.mapper.IDoctorMapper;
import com.nefu.huiyi.service.DoctorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Service
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    private  IDoctorMapper doctorMapper;

    @Override
    public Doctor saveDoctor(Doctor doctor) {
        doctorMapper.insert(doctor);
        return doctor;
    }

    @Override
    public boolean deleteDoctor(Integer id) {
        return doctorMapper.deleteById(id) > 0;
    }

    @Override
    public Doctor updateDoctor(Doctor doctor) {
        doctorMapper.updateById(doctor);
        return doctorMapper.selectById(doctor.getId());
    }

    @Override
    public Doctor getDoctorById(Integer id) {
        return doctorMapper.selectById(id);
    }

    @Override
    public List<Doctor> findAll() {
        return doctorMapper.selectList(null);
    }

    @Override
    public IPage<Doctor> getDoctorPage(Page<Doctor> page, String keyword) {
        LambdaQueryWrapper<Doctor> wrapper = new LambdaQueryWrapper<>();
//        List<Doctor> doctors = doctorMapper.findAll();
        if (keyword != null && !keyword.isEmpty()) {
            wrapper.like(Doctor::getName, keyword)
                    .or().like(Doctor::getDepartment, keyword)
                    .or().like(Doctor::getTitle, keyword);
        }
        return doctorMapper.selectPage(page, wrapper);
    }



}